const date = new Date()
const years = []
const months = []
const days = []

for (let i = 2018; i <= date.getFullYear(); i++) {
  years.push(i)
}

for (let i = 1; i <= 12; i++) {
  months.push(i)
}

for (let i = 1; i <= 31; i++) {
  days.push(i)
}

var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ifscroll:false,
    wrapDate:false,
    wrapCategory: false,
    animationData: {},
    cStatus:false,
    dStatus: false,
    oStatus: false,
    categoryName:"全部科目",
    listCategory:[

      {
        "name": "全部科目",
        "id": 1
      },
      {
        "name": "收入",
        "id": 2
      },
      {
        "name": "支出",
        "id": 3
      },

    ],
    orderName:"订单来源",
    orderSelect:1,
    listOrder: [

      {
        "name": "订单来源",
        "id": 1
      },
      {
        "name": "普通订单",
        "id": 2
      },
      {
        "name": "企业订单",
        "id": 3
      },

    ],
    categorySelect:1,
    years: years,
    year: date.getFullYear(),
    months: months,
    month: date.getMonth() + 1,
    days: days,
    day: 2,
    value: [9999, 1, 1],
    wxType: "",
    monthStatus:true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({ wxType: app.globalData.wxType });
  },

  //显示弹窗事件
  wrapCategorySelect: function (e) {
    console.log(e);
    console.log(e.currentTarget.dataset.index);

    var that = this;
    that.data.indexNumber = e.currentTarget.dataset.index;

    // 创建一个动画实例
    var animation = wx.createAnimation({
      // 动画持续时间
      duration: 500,
      // 定义动画效果，当前是匀速
      timingFunction: 'linear'
    })
    // 将该变量赋值给当前动画
    that.animation = animation
    // 先在y轴偏移，然后用step()完成一个动画
    animation.translateY(-200).step()
    // 用setData改变当前动画
    that.setData({
      // 通过export()方法导出数据
      animationData: animation.export(),
      // 改变view里面的Wx：if
      //wrapCategory: true,
      ifscroll: true,
      wrapCategory: !that.data.wrapCategory,
      cStatus: !that.data.cStatus,
      wrapDate:false,
      dStatus: false,
      wrapOrder: false,
      oStatus: false,
      
    })
    // 设置setTimeout来改变y轴偏移量，实现有感觉的滑动
    setTimeout(function () {
      animation.translateY(0).step()
      that.setData({
        animationData: animation.export(),
        
      })
    }, 0)
  },
  //隐藏弹窗事件
  hideModal: function (e) {
    var that = this;
    var animation = wx.createAnimation({
      duration: 1000,
      timingFunction: 'linear'
    })
    that.animation = animation
    animation.translateY(-200).step()
    that.setData({
      animationData: animation.export()

    })
    setTimeout(function () {
      animation.translateY(0).step()
      that.setData({
        ifscroll: false,
        animationData: animation.export(),
        wrapCategory: false,
        cStatus:false,
        wrapDate: false,
        dStatus: false,
        wrapOrder: false,
        oStatus: false
      })
    }, 100)
  },

//categoryList
  categoryList: function (e) {
    console.log(e)
    var that = this;
    that.setData({//把选中值放入判断值
      categorySelect: e.currentTarget.dataset.select,
      categoryName: e.currentTarget.dataset.text
    })
    console.log(e.currentTarget.dataset.text);
    that.hideModal();
  },

  //日期选择
  wrapDateSelect:function(){
    var that = this;
    var animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'linear'
    })
    that.animation = animation
    animation.translateY(-200).step()
    that.setData({
      ifscroll: true,
      animationData: animation.export(),
      wrapDate: !that.data.wrapDate,
      dStatus: !that.data.dStatus,
      wrapCategory: false,
      cStatus: false,
      wrapOrder: false,
      oStatus: false,
      monthStatus:false

    })
    setTimeout(function () {
      animation.translateY(0).step()
      that.setData({
        animationData: animation.export(),

      })
    }, 0)
   

  },

  bindChange: function (e) {
    var that = this;
    const val = e.detail.value;
    var year = that.data.years[val[0]];
    var month = that.data.months[val[1]];
    if (year == date.getFullYear() && month == date.getMonth() + 1){
      that.setData({ monthStatus: true});
    }
    that.setData({
      year: that.data.years[val[0]],
      month: that.data.months[val[1]],
    //  day: this.data.days[val[2]]
    })
    that.hideModal();
  },

//订单来源选择
  wrapOrderSelect: function(){
    var that = this;
    var animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'linear'
    })
    that.animation = animation
    animation.translateY(-200).step()
    that.setData({
      ifscroll: true,
      animationData: animation.export(),
      wrapOrder: !that.data.wrapOrder,
      oStatus: !that.data.oStatus,
      wrapCategory: false,
      cStatus: false,
      wrapDate: false,
      dStatus: false

    })
    // 设置setTimeout来改变y轴偏移量，实现有感觉的滑动
    setTimeout(function () {
      animation.translateY(0).step()
      that.setData({
        animationData: animation.export(),

      })
    }, 0)
   
   
  },
  //orderList
  orderList: function (e) {
    console.log(e)
    var that = this;
    that.setData({//把选中值放入判断值
      orderSelect: e.currentTarget.dataset.select,
      orderName: e.currentTarget.dataset.text
    })
    that.hideModal();
  },

  noScroll: function () {
    //微信小程序有bind和catch两种事件绑定方法，bind事件绑定不会阻止冒泡事件向上冒泡，catch事件绑定可以阻止冒泡事件向上冒泡。我们使用catch绑定手指触摸事件，然后他的父节点就不会收到事件冒泡，这样就实现了禁止页面上下滑动
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})